#include "Shape2D.hh"

#    include "tools/Matrix.hh"


Shape2D::Shape2D() : _shaderTst("tst")
{
    float vertex[] = {-1.0f, -1.0f, 0.0f,
                      1.0f, -1.0f, 0.0f,
                      0.0f,  1.0f, 0.0f};

    unsigned int nbVertex = 9;
    _vertex = new float[nbVertex];

    for (unsigned int i(0); i < nbVertex; ++i)
        _vertex[i] = vertex[i];


    glBufferData(GL_ARRAY_BUFFER, sizeof(_vertex), _vertex, GL_STATIC_DRAW);
}

Shape2D::~Shape2D()
{
    //dtor
}



GLuint Shape2D::getProgramId()
{
    return _shaderTst.getProgramId();
}


void Shape2D::init(Matrix MVP, GLuint vertexbuffer, GLuint MatrixID)
{
    // Give our vertices to OpenGL.

  glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);



glEnableVertexAttribArray(0); //
    // 1rst attribute buffer : vertices
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glVertexAttribPointer(
       0,        // attribute 0. No particular reason for 0, but must match the layout in the shader.
       3,        // size
       GL_FLOAT, // type
       GL_FALSE, // normalized?
       0,        // stride
       (void*)0  // array buffer offset
    );


    glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle

    glDisableVertexAttribArray(0);
}
